// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: leon

#pragma once

#include <memory>
#include <string>

#include "coin2/base/string_util.h"
#include "coin2/exchange/base/symbology/currency.h"
#include "coin2/exchange/base/symbology/util.h"

namespace coin2::exchange::bitflyer_futures::symbology {

class BitflyerCurrency : public base::symbology::Currency,
                         public base::symbology::CurrencyFromStrMixin<BitflyerCurrency> {
 public:
  using ExchangeType = base::market::ExchangeType;
  using MarketType = base::market::MarketType;
  using Currency = base::symbology::Currency;
  using base::symbology::Currency::native_currency;

 public:
  explicit BitflyerCurrency(const std::string& currency)
      : Currency(currency, ToNativeCurrency(currency).value(), ExchangeType::Bitflyer) {}

  static std::unique_ptr<BitflyerCurrency> FromNativeStrImpl(
      const std::string& native_currency_str,
      int64_t resolve_timestamp) {
    auto currency = FromNativeCurrency(native_currency_str);
    if (!currency) {
      return {};
    }
    return std::make_unique<BitflyerCurrency>(currency.value());
  }

  static std::unique_ptr<BitflyerCurrency> FromNormStrImpl(
      const std::string& currency_str,
      int64_t resolve_timestamp) {
    auto native_currency = ToNativeCurrency(currency_str);
    if (!native_currency) {
      return {};
    }
    return std::make_unique<BitflyerCurrency>(native_currency.value());
  }

 private:
  static std::optional<std::string> ToNativeCurrency(const std::string& currency_str) {
    if (StringIsLower(currency_str)) {
      return {};
    }
    // TODO(leon): Verify if valid currency.
    return StringToUpperCopy(currency_str);
  }

  static std::optional<std::string> FromNativeCurrency(const std::string& native_currency_str) {
    if (StringIsLower(native_currency_str)) {
      return {};
    }
    // TODO(leon): Verify if valid native currency.
    return StringToUpperCopy(native_currency_str);
  }
};

}  // namespace coin2::exchange::bitflyer_futures::symbology
